package com.shiguo365.market.presenter.implement;

import android.app.Activity;
import android.support.annotation.NonNull;
import android.util.Log;

import com.alibaba.fastjson.JSONObject;
import com.shiguo365.market.display.view.IMarketPriceView;
import com.shiguo365.market.presenter.contract.IMarketPricePresenter;

import java.util.List;

import biz.yfsoft.api.ae.api.AEClient;
import biz.yfsoft.api.ae.api.AEParam;
import biz.yfsoft.api.ae.api.BaseAECallback;

/**
 * Created by CoderA on 2016/7/9.
 */
public class MarketPricePresenter implements IMarketPricePresenter {

    private static final String TAG = "MarketPricePresenter";
    private final Activity mActivity;
    private final IMarketPriceView mView;

    public MarketPricePresenter(@NonNull Activity activity, @NonNull IMarketPriceView view) {
        this.mActivity = activity;
        this.mView = view;
    }


    @Override
    public void getProductList(String tagCode, int page,int size) {

        AEClient _client = new AEClient("shiguo.data.getProlistByTag");
        final AEParam aeParam =new AEParam();
        aeParam.set("tag",tagCode);
        aeParam.set("page",page);
        aeParam.set("size",size);
        _client.call(aeParam,new BaseAECallback() {

            @Override
            public void onSuccess(List<JSONObject> a) {
                Log.d(TAG,a.toString());
                mView.onRefreshProductListResultOk(a);
            }

            @Override
            public void onError( String errno, String message) {
                Log.e(TAG,"onFailure ......." + errno + ";message:" + message);
            }

            @Override
            public void onFinally(String s) {
                mView.onRefreshProductListFinish();
            }
        });
    }

    @Override
    public void updateCart(Integer uid, Integer pid) {
        AEClient _client = new AEClient("shiguo.cart.updateCart");

        final AEParam aeParam =new AEParam().set("uid",uid).set("pid",pid);

        _client.call(aeParam,new BaseAECallback() {
            @Override
            public void onStart() {
            }

            @Override
            public void onSuccess(JSONObject jsonObject) {
                Log.d(TAG,"onSuccess ......." + jsonObject);
            }

            @Override
            public void onError( String errno, String message) {
                Log.e(TAG,"onError ......." + errno);
            }

            @Override
            public void onFinally(String s) {
                Log.d(TAG,"onFinally ......." + s);
                //mCartView.onGetCartFinished();
            }
        });
    }
}
